<template>
	<view v-if="hasdata"><uni-indexed-list :options="dataLists" :show-select="false" @click="bindClick" /></view>
	<view v-else>
		<view class="container_row col">
			<view class="container_image"><image src="../../static/img/nopatients.png" mode="aspectFill"></image></view>
			<view class="text">暂无患者，快去邀请您的患者吧~</view>
		</view>
	</view>
</template>

<script>
import uniIndexedList from '@/components/uni-indexed-list/uni-indexed-list.vue';
import { BASE_URL, consumers,startChat,getSingleChatStatus } from '@/utils/api';
import Pinyin from '@/utils/ChinesePY.js';

// #ifdef APP-PLUS
		const rongIm = uni.requireNativePlugin('GZF-RongIM');
	// #endif
	
export default {
	components: {
		uniIndexedList
	},
	data() {
		return {
			hasdata: false,
			name: '',
			dataLists: [
				{
					letter: 'A',
					data: []
				},
				{
					letter: 'B',
					data: []
				},
				{
					letter: 'C',
					data: []
				},
				{
					letter: 'D',
					data: []
				},
				{
					letter: 'E',
					data: []
				},
				{
					letter: 'G',
					data: []
				},
				{
					letter: 'H',
					data: []
				},
				{
					letter: 'I',
					data: []
				},
				{
					letter: 'J',
					data: []
				},
				{
					letter: 'K',
					data: []
				},
				{
					letter: 'L',
					data: []
				},
				{
					letter: 'M',
					data: []
				},
				{
					letter: 'N',
					data: []
				},
				{
					letter: 'O',
					data: []
				},
				{
					letter: 'P',
					data: []
				},
				{
					letter: 'Q',
					data: []
				},
				{
					letter: 'R',
					data: []
				},
				{
					letter: 'S',
					data: []
				},
				{
					letter: 'T',
					data: []
				},
				{
					letter: 'U',
					data: []
				},
				{
					letter: 'V',
					data: []
				},
				{
					letter: 'W',
					data: []
				},
				{
					letter: 'X',
					data: []
				},
				{
					letter: 'Y',
					data: []
				},
				{
					letter: 'Z',
					data: []
				},
				{
					letter: '#',
					data: []
				}
			]
		};
	},
	/**
	 *  点击导航栏 buttons 时触发
	 */
	onNavigationBarButtonTap() {
		uni.navigateTo({
			url: '/pages/patientList/detail/patientsearch'
		});
	},
	methods: {
		bindClick(e) {
			console.log('点击item，返回数据' + JSON.stringify(e));
			this.getSingleChatStatus(e);
		},
		async getSingleChatStatus(item){
			let res = await getSingleChatStatus(item.item.id);
			if(res.status == 0){
				item.item.expiryDate = res.data.expiryDate+"";
				item.item.status = res.data.status;
				item.item.targetId = item.item.id;
				console.log(item);
				rongIm.startTalk(JSON.stringify(item.item));
			}
		},
		async getConsumers() {
			let that = this;
			let res = await consumers();
			if (res.status == 0) {
				console.log(res);
				this.dataLists.map(v => {
					res.data.map(item => {
						let firstChar = item.name.substr(0, 1);
						//获取姓名首字母（大写）
						let letter = Pinyin.getWordsCode(firstChar);
						if (v.letter == letter) {
							v.data.push(item);
						}
						this.hasdata=true;
					});
				});
			} else {
				this.hasdata=false;
				uni.showToast({
					icon: 'none',
					title: res.message,
					duration: 1000
				});
			}
		}
	},
	onLoad() {
		this.getConsumers();
	}
};
</script>

<style lang="scss">
.container_row {
	.container_image {
		margin-top: 169upx;

		image {
			width: 459upx;
			height: 290upx;
			border-radius: 50%;
		}
	}

	.text {
		height: 32upx;
		font-size: 34upx;
		font-weight: 400;
		color: #bbd5ef;
		margin-top: 62upx;
	}
}
</style>
